package com.ruoyi.system.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.domain.JxStudentProgress;
import com.ruoyi.system.mapper.JxStudentProgressMapper;
import com.ruoyi.system.service.IJxStudentProgressService;

@Service
public class JxStudentProgressServiceImpl implements IJxStudentProgressService {
    @Autowired
    private JxStudentProgressMapper mapper;

    @Override
    public JxStudentProgress selectById(Long id) { return mapper.selectById(id); }

    @Override
    public List<JxStudentProgress> selectList(JxStudentProgress query) { return mapper.selectList(query); }

    @Override
    public int insert(JxStudentProgress entity) { return mapper.insert(entity); }

    @Override
    public int update(JxStudentProgress entity) { return mapper.update(entity); }

    @Override
    public int deleteByIds(Long[] ids) { return mapper.deleteByIds(ids); }

    @Override
    public int addHours(Long progressId, int delta) { return mapper.addHours(progressId, delta); }

    @Override
    public int updateProgressStatus(Long studentId, Long subjectId, String status) {
        JxStudentProgress query = new JxStudentProgress();
        query.setStudentId(studentId);
        query.setSubjectId(subjectId);
        List<JxStudentProgress> list = mapper.selectList(query);
        if (list != null && !list.isEmpty()) {
            JxStudentProgress progress = list.get(0);
            progress.setStatus(status);
            if ("完成".equals(status)) {
                progress.setCompletedAt(new java.util.Date());
            }
            return mapper.update(progress);
        }
        return 0;
    }
}


